#include "Control_CheckBox.h"

#include "Control_Menu.h"

#include "Host.h"

#include "RendererComponent.h"

using namespace gui;


Control_CheckBox::Control_CheckBox(CallbackGetBoolValue NewCallbackGetValue, CallbackSetBoolValue NewCallbackSetValue, std::string NewCaption, Vec<2, float> NewFontSize, ColorRGBA<unsigned char> NewForeColor, ColorRGBA<unsigned char> NewColorBack1, ColorRGBA<unsigned char> NewColorBack2, ColorRGBA<unsigned char> NewColorFalse, ColorRGBA<unsigned char> NewColorTrue, Vec<2, float> NewPos, Vec<2, float> NewSize, Control_Menu* NewParentMenu, Host& NewParentHost) :
Control_TextHover(NewCaption, NewFontSize, NewForeColor, NewColorBack1, NewColorBack2, NewPos, NewSize, NewParentMenu, NewParentHost),
Value(true),
LastValue(true),
CallbackGetValue(NewCallbackGetValue),
CallbackSetValue(NewCallbackSetValue),
ColorTrue(NewColorTrue),
ColorFalse(NewColorFalse)
{


}

Control_CheckBox::~Control_CheckBox()
{
}


void Control_CheckBox::Refresh()
{
	Value = CallbackGetValue();
	if (Value == !LastValue)
	{
		LastValue = Value;
		HostVertexFixModification();
	}
}

void Control_CheckBox::MouseDownLeft()
{
	Value = !Value;
	LastValue = Value;
	CallbackSetValue(Value);
	HostVertexFixModification();
}


void Control_CheckBox::UpdateVerticesFix(RendererComponent& Renderer)
{
	
	Control_TextHover::UpdateVerticesFix(Renderer);

	if (LastValue)
	{
		Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
			ParentMenuPos->X + (Pos.X + Size.X) - Size.Y,
			-ParentMenuPos->Y + (-Pos.Y),
			*ParentMenuLayer,
			ColorTrue.R, ColorTrue.G, ColorTrue.B, ColorTrue.A);

		Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
			ParentMenuPos->X + (Pos.X + Size.X) - Size.Y,
			-ParentMenuPos->Y + (-Pos.Y - Size.Y),
			*ParentMenuLayer,
			ColorTrue.R, ColorTrue.G, ColorTrue.B, ColorTrue.A);

		Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
			ParentMenuPos->X + (Pos.X + Size.X),
			-ParentMenuPos->Y + (-Pos.Y - Size.Y),
			*ParentMenuLayer,
			ColorTrue.R, ColorTrue.G, ColorTrue.B, ColorTrue.A);

		Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
			ParentMenuPos->X + (Pos.X + Size.X),
			-ParentMenuPos->Y + (-Pos.Y),
			*ParentMenuLayer,
			ColorTrue.R, ColorTrue.G, ColorTrue.B, ColorTrue.A);
	}
	else 
	{
		Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
			ParentMenuPos->X + (Pos.X + Size.X) - Size.Y,
			-ParentMenuPos->Y + (-Pos.Y),
			*ParentMenuLayer,
			ColorFalse.R, ColorFalse.G, ColorFalse.B, ColorFalse.A);

		Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
			ParentMenuPos->X + (Pos.X + Size.X) - Size.Y,
			-ParentMenuPos->Y + (-Pos.Y - Size.Y),
			*ParentMenuLayer,
			ColorFalse.R, ColorFalse.G, ColorFalse.B, ColorFalse.A);

		Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
			ParentMenuPos->X + (Pos.X + Size.X),
			-ParentMenuPos->Y + (-Pos.Y - Size.Y),
			*ParentMenuLayer,
			ColorFalse.R, ColorFalse.G, ColorFalse.B, ColorFalse.A);

		Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
			ParentMenuPos->X + (Pos.X + Size.X),
			-ParentMenuPos->Y + (-Pos.Y),
			*ParentMenuLayer,
			ColorFalse.R, ColorFalse.G, ColorFalse.B, ColorFalse.A);
	}

}



